package jmine.tec.report.pos;

import java.io.IOException;
import java.io.OutputStream;

import jmine.tec.report.api.Report;
import jmine.tec.report.api.ReportElement;
import jmine.tec.report.export.ReportFileExporter;
import jmine.tec.report.impl.table.pos.CellRendererPosRegistry;

/**
 * @author katsuo.ogawa
 */
public class ReportPosExporter implements ReportFileExporter {

    public static final String RENDERER_TYPE = "posicional";

    private ReportRendererPosRegistry reportRendererRegistry;

    private CellRendererPosRegistry cellRendererRegistry;

    private String logoPath;

    /**
     * {@inheritDoc}
     */
    public void export(OutputStream outputStream, Report report) throws IOException {
        for (ReportElement element : report.getElements()) {
            ReportElementPosRenderer renderer = this.reportRendererRegistry.getRenderer(element.getRendererType());
            renderer.render(outputStream, element);
        }
    }

    /**
     * {@inheritDoc}
     */
    public String getLogoPath() {
        return this.logoPath;
    }

    /**
     * @param logoPath the logoPath to set
     */
    public void setLogoPath(String logoPath) {
        this.logoPath = logoPath;
    }

    /**
     * {@inheritDoc}
     */
    public String getRendererType() {
        return RENDERER_TYPE;
    }

    /**
     * @return the reportRendererRegistry
     */
    public ReportRendererPosRegistry getReportRendererRegistry() {
        return this.reportRendererRegistry;
    }

    /**
     * @return the cellRendererRegistry
     */
    public CellRendererPosRegistry getCellRendererRegistry() {
        return this.cellRendererRegistry;
    }

    /**
     * @param reportRendererRegistry the reportRendererRegistry to set
     */
    public void setReportRendererRegistry(ReportRendererPosRegistry reportRendererRegistry) {
        this.reportRendererRegistry = reportRendererRegistry;
    }

    /**
     * @param cellRendererRegistry the cellRendererRegistry to set
     */
    public void setCellRendererRegistry(CellRendererPosRegistry cellRendererRegistry) {
        this.cellRendererRegistry = cellRendererRegistry;
    }

    /**
     * {@inheritDoc}
     */
    public String getContentType() {
        return "text/plain";
    }

    /**
     * {@inheritDoc}
     * 
     * @see jmine.tec.report.export.ReportFileExporter#getFileSuffix()
     */
    public String getFileSuffix() {
        return ".txt";
    }

}
